﻿Imports System.Data.OleDb
Public Class addNewIsland
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click


        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(fup_picture.FileName)
        If fup_picture.HasFile Then
            fup_picture.SaveAs(Server.MapPath("pictures") & "/" & newFileName)
        End If



        Dim sql As String = "INSERT INTO tour (PhoneNumber,MitchelinStars,IslandName,IslandPicture,Postcode,Website,AddedBy) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("IslandConnectionString").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_number.Text)
        cmd.Parameters.AddWithValue("@f2", rbl_mitchelinstars.SelectedValue)
        cmd.Parameters.AddWithValue("@f3", tb_name.Text)
        cmd.Parameters.AddWithValue("@f4", "Pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f5", tb_postcode.Text)
        cmd.Parameters.AddWithValue("@f6", tb_website.Text)
        cmd.Parameters.AddWithValue("@f7", User.Identity.Name)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("list.aspx")

    End Sub

    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function
End Class

